<?php
namespace app\index\controller;
header("Content-type:text/html;charset=utf-8");

use app\admin\validate\UserRule;
use app\common\controller\Frontend;
use app\common\model\Category;
use think\Cache;
use think\view\driver\Think;
use app\common\model\App;


class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {


        $Category=new Category();
        $category=$Category->getCategoryArray();
        $this->assign('category',$category);

        $mod=model('App');
        $cate=$mod->getCateNameList();
        $this->assign('cate',$cate);

        //获取首页所需数据
        $index_data=$this->get_index_data();
        $this->assign($index_data);

        return $this->fetch("index/index");
    }


    public function get_index_data(){

        $cache_name="index_data";
        //Cache::rm($cache_name);
        if(Cache::has($cache_name)){
            $index_data=Cache::get($cache_name);
        }else{
            $dj=db('app')->where('cate_name','单机')->limit(30)->select();
            $wy=db('app')->where('cate_name','网游')->limit(30)->select();
            $bt=db('app')->where('cate_name','BT')->limit(30)->select();
            $sy=db('app')->where('cate_name','网游')->limit(6)->select();
            $yy=db('app')->where('cate_name','应用')->limit(7)->select();
            $and_app=db('app')->where('cate_name','应用')->limit(30)->select();
            $xw=db('news')->limit(21)->select();
            $yxdh=db('app')->limit(10)->select();
            $index_data=[
                "dj"=>$dj,
                "wy"=>$wy,
                "bt"=>$bt,
                "sy"=>$sy,
                "yy"=>$yy,
                "and_app"=>$and_app,
                "xw"=>$xw,
                "yxdh"=>$yxdh,
            ];
            Cache::set($cache_name,$index_data,86400);
        }

        return $index_data;

    }




}

